package com.crm.exception;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * Class Description:项目中所有exception 的基类 
 * 
 * <pre>
 *  Filename        : BusinessException.java 
 *  Date			   : 2008-08-18
 *  Creator         : liuqing
 *  Revised Description 
 *  ----------------------------------------------
 *  ver	revised date	reviser	revised contents
 *  0.1   2008-08-18       liuqing            create
 *  ----------------------------------------------
 *  
 * </pre>
 */
@SuppressWarnings("serial")
public class BusinessException extends Exception {
	
	protected Throwable rootCause;  //支持原始异常
	
	private List<BusinessException> exceptions =new ArrayList<BusinessException>();//支持多样化异常，exceptions属性存放所有嵌套的异常类
	
	private Object values[];   //支持复合式的消息，values属性制定复合式消息中的参数
	
	private String message; //制定消息Key
	
	public BusinessException(){
		
	}
	
	public BusinessException(String message){
		this.message=message;
	}
	
	public BusinessException(Throwable rootCause){
		super(rootCause);
		this.rootCause=rootCause;
	}
	
	public BusinessException(String message,Object value){
		super(message);
		this.message=message;
		values=new Object[]{value};
	}
	
	public BusinessException(String message,Object[] values){
		super(message);
		this.message=message;
		this.values=values;
	}
	
	public BusinessException(String message,Throwable rootCause,Object value){
		super(message);
		this.message=message;
		this.rootCause=rootCause;
		values=new Object[]{value};
	}
	
	public BusinessException(String message,Throwable rootCause,Object[] values){
		super(message);
		this.message=message;
		this.rootCause=rootCause;
		this.values=values;
	}
	
	public List getExceptions() {
		return exceptions;
	}
	
	public void addExcpetion(BusinessException ex){
		exceptions.add(ex);
	}
	
	public void printStackTrace(){
		super.printStackTrace(System.err);
	}
	
	public void printStackTrace(PrintStream outStream){
		super.printStackTrace(new PrintWriter(outStream));
	}
	
	public void printStackTrace(PrintWriter writer){
		super.printStackTrace(writer);
		if(getRootCause()!=null){
			getRootCause().printStackTrace(writer);
		}
		writer.flush();
	}
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Throwable getRootCause() {
		return rootCause;
	}

	public void setRootCause(Throwable rootCause) {
		this.rootCause = rootCause;
	}

	public Object[] getValues() {
		return values;
	}

	public void setValues(Object[] values) {
		this.values = values;
	}

	
	
	
}
